#include "MenuScene.h"
#include "ShareComponents.h"
#include "RSManager.h"
#include "StateManager.h"
#include "MainGame.h"

MenuScene::MenuScene(HINSTANCE hIns, char* windowName, int w, int h) :FWGame(hIns, windowName, w,h)
{
	
}
MenuScene::MenuScene(FWGame* fwgame) : FWGame(fwgame)
{
	id_scene= MENU;
}

MenuScene::~MenuScene()
{

}
void MenuScene::load()
{
	
	_background = RSManager::getInstance()->getSprite(MENU_BACKGROUND);
	_option_icon = RSManager::getInstance()->getSprite(OPTION_ICON);
	_background_pos = D3DXVECTOR2(640, 0);
	_icon_pos = D3DXVECTOR2(100, 140);
	_is_oneplayer = true;
	_is_press_enter = false;
	_isrender = true;
	delay = 0;
	delay2 = 0;
	delay3 = 0;

}
void MenuScene::update(float time)
{
	delay += time;
	
	gl_camera->Update(D3DXVECTOR2(0, 0));
	if (_background_pos.x >0)
	{
		if (delay > 100)
		{
			delay = 0;
			_background_pos.x -=10;
		}
		if(gl_keyboard->isKeyPressed(DIK_SPACE) || gl_keyboard->isKeyPressed(DIK_RETURN))
			_background_pos.x=0;
	_is_press_enter ==false;
	}
	else
	{
		//xu li nhan space
		delay2 += time;
		if (gl_keyboard->isKeyPressed(DIK_SPACE) && !_is_press_enter)
		{
			delay2 = 0;
			if (_icon_pos.y == 140)
			{	//2 nguoi choi
				_icon_pos.y = 110;
				_is_oneplayer= false;
				
			}

			else
			{	//1 nguoi choi
				_icon_pos.y = 140;
				_is_oneplayer = true;
			}
			_background_pos.x = 0;
			
		}

		if (gl_keyboard->isKeyDown(DIK_RETURN))
		{
			_is_press_enter = true;
		}

		_isrender = false;
		if (delay > 500 && _is_press_enter ==true)
		{
			delay = 0;
			_isrender = true;
		}
		if (_is_press_enter)
			delay3 += time;
		// neu khong enter, thoi gian doi nguoi choi tinh tu khi nhan space
		if ((delay2 > 5000 && !_is_press_enter) ||( _is_press_enter && delay3>2000))
		{
			id_next_scene=MIDDEL_SCENE;
		}
		
		
	}
}
void MenuScene::render()
{
	_background->Render(_background_pos);
	gl_graphic->sDraw("PLAYER SELECT", _background_pos + D3DXVECTOR2(100,290),D3DCOLOR_XRGB(188,188,188));
	gl_graphic->sDraw("        TM AND @ 1988\n KONAMI INDUSTRYCO.,LTD\n             LICENSED BY\n NITENDO OF AMARICA INC",
		_background_pos + D3DXVECTOR2(100,380),D3DCOLOR_XRGB(188,188,188));
	if (_background_pos.x==0)
		_option_icon->Render(_icon_pos);
		if (!_is_press_enter)
	{
		gl_graphic->sDraw("1  PLAYER", _background_pos + D3DXVECTOR2(140,320),D3DCOLOR_XRGB(188,188,188));
		gl_graphic->sDraw("2  PLAYERS", _background_pos + D3DXVECTOR2(140,350),D3DCOLOR_XRGB(188,188,188));

	}
	else 
	{
		if((_isrender)|| (_is_oneplayer && !_isrender ))
			gl_graphic->sDraw("2  PLAYERS", _background_pos + D3DXVECTOR2(140,350),D3DCOLOR_XRGB(188,188,188));
		if((_isrender)|| (!_is_oneplayer && !_isrender ))
			gl_graphic->sDraw("1  PLAYER", _background_pos + D3DXVECTOR2(140,320),D3DCOLOR_XRGB(188,188,188));		
	}
}
void MenuScene::shutdown()
{

}